<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div>
        <!-- <form enctype="multipart/formData" id="frm"> -->
            <input  type="file" id="upload01" name="imagefile"   />
            <img width="150px" height="150px" src=""/>
            <input  type="button" class="btn" value="上传"/>
        <!-- </div> -->
    </form>
        <img src=""/>
        <script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/jquery/1.9.1/jquery.min.js"></script> 
        <script type="text/javascript">
            var fileId;
            $(".btn").click(function(){
                fileId = $(this).siblings('input[type="file"]').attr("id");
                imgup( fileId );
            })
            
            /*$("#upload").change(function(){//这个是显示图片的
                var strsrc=getObjectURL(this.files[0]);//这个就是地址了
                $("img").attr("src",strsrc);
            })*/
            
            /*function getObjectURL(file) {//这个是获取上传图片的本地地址
                var url = null ; 
                if (window.createObjectURL!=undefined) { // basic
                    url = window.createObjectURL(file) ;
                } else if (window.URL!=undefined) { // mozilla(firefox)
                    url = window.URL.createObjectURL(file) ;
                } else if (window.webkitURL!=undefined) { // webkit or chrome
                    url = window.webkitURL.createObjectURL(file) ;
                }
                return url ;
            }*/
            
            function imgup( img_id ){
                var formData = new FormData($('#frm'));
                formData.append("file",$("#"+img_id+"")[0].files[0]);
                $.ajax({
                    type:"post",
                    url:"{:url('goods/upload', '', false)}",
                    async:true,
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    success : function(res){
                        alert($res.filename);
                        console.log(res.access_url)
                        //把返回的图片地址赋给对应的img标签
                        $("#"+img_id+"").siblings("img").attr("src",res.access_url);
                        
                    },
                    error : function(res){
                        console.log(res.access_url);
                    }
                })
            }
        </script>
    </body>
</html>